import { Component, OnInit, Output, EventEmitter} from '@angular/core';
import {Store, select} from '@ngrx/store';
import {Observable} from 'rxjs';
import {Project} from '../../domain';
import * as actions from '../../actions/project.action';
import * as fromRoot from '../../reducers';
@Component({
  selector: 'app-sidebar',
  templateUrl: './sidebar.component.html',
  styleUrls: ['./sidebar.component.scss']
})
export class SidebarComponent implements OnInit {
  projects$: Observable <Project []>;
  @Output() navClick = new EventEmitter <void>();
  constructor(private store$: Store<fromRoot.State>) {
    this.projects$ = this.store$.pipe(select(fromRoot.getProjects));
  }

  ngOnInit() {
  }
  onNavClick() {
   this.navClick.emit();
  }
  onPrjClick(prj) {
     this.store$.dispatch(new actions.SelectProjectAction(prj));
     this.navClick.emit();
  }
}
